package com.ceba.test.modules.email.logicService;

import com.ceba.test.modules.email.entity.EmailEntity;
import com.ceba.test.modules.email.entity.EmailEntitySubject;
import com.ceba.test.modules.email.entity.EmailSubject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public abstract class BaseEmailMannager implements BaseEmail{
	static Logger logger = LoggerFactory.getLogger(BaseEmailMannager.class);
	private EmailEntity emailEntity;
	private BaseEmailMannager baseEmailMannager;
	
	public BaseEmailMannager(EmailEntity emailEntity, BaseEmailMannager baseEmailMannager) {
		this.emailEntity=emailEntity;
		this.baseEmailMannager=baseEmailMannager;
	}
	
	public BaseEmailMannager(EmailEntity emailEntity) {
		this.emailEntity=emailEntity;
		this.baseEmailMannager=this;
	} 
	
	@Override
	public String send() {
		String content=baseEmailMannager.content();
		String subject=baseEmailMannager.subject();
		this.emailEntity.setContent(content);
		this.emailEntity.setSubject(subject);
		EmailSubject emailSubject=new EmailEntitySubject(emailEntity);
		try {
			return emailSubject.send();
		} catch (Exception e) {
			logger.debug(e.getMessage());
			e.printStackTrace();
		}
		return null;
	}

	public EmailEntity getEmailEntity() {
		return emailEntity;
	}

	public void setEmailEntity(EmailEntity emailEntity) {
		this.emailEntity = emailEntity;
	}

	public BaseEmailMannager getBaseEmailMannager() {
		return baseEmailMannager;
	}

	public void setBaseEmailMannager(BaseEmailMannager baseEmailMannager) {
		this.baseEmailMannager = baseEmailMannager;
	}
	
	
}
